package com.wl.designpattern.composite;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by wangliang on 2021/2/27.
 */
public class AQColumn extends AQPageElement {
    private List<AQPageElement> mPageElements = new ArrayList<>();//用来保存页面元素

    public AQColumn(String name) {
        super(name);
    }

    public void addPageElement(AQPageElement pageElement) {
        mPageElements.add(pageElement);
    }

    public void rmPageElement(PageElement pageElement) {
        mPageElements.remove(pageElement);
    }

    public void clear() {
        mPageElements.clear();
    }

    @Override
    public void print(String placeholder) {
        System.out.println(placeholder + "└──" + getName());
        Iterator<AQPageElement> i = mPageElements.iterator();
        while (i.hasNext()) {
            AQPageElement pageElement = i.next();
            pageElement.print(placeholder + "   ");
        }
    }
}
